import play.api._

import models._
import anorm._

object Global extends GlobalSettings {
  override def onStart(app: Application) {
    InitialData.insert()
  }
}

/**
 * Initial set of data to be imported 
 * in the sample application.
 */
object InitialData {
  def date(str: String) = new java.text.SimpleDateFormat("yyyy-MM-dd").parse(str)
  
  def insert() = {
    if (User.findAll.isEmpty) {
      Seq(
        User("user@studykun.com", "Study Kun", "secret"),
        User("maxime@sample.com", "Maxime Dantec", "secret"),
        User("sadek@sample.com", "Sadek Drobi", "secret"),
        User("erwan@sample.com", "Erwan Loisant", "secret")
      ).foreach(User.create)

      Seq(
        Deck(Id(1), "Lesson 1") -> Seq("user@studykun.com", "maxime@sample.com", "sadek@sample.com", "erwan@sample.com"),
        Deck(Id(2), "Lesson 2") -> Seq("user@studykun.com", "erwan@sample.com"),
        Deck(Id(3), "Lesson 3") -> Seq("user@studykun.com", "erwan@sample.com"),
        Deck(Id(4), "Lesson 4") -> Seq("user@studykun.com", "erwan@sample.com")
      ).foreach {
        case (project,members) => Deck.create(project, members)
      }
    }
  }
}
